package cc.comac.mom.service.impl;

import java.util.List;

import cc.comac.mom.api.UsersSelCmd;
import cc.comac.mom.model.table.jflow.UsersDO;
import cc.comac.mom.util.user.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cc.comac.mom.api.QualityAsrCheckFormService;
import cc.comac.mom.bean.QualityAsrCheckForm;
import cc.comac.mom.bean.QualityReject;
import cc.comac.mom.datahandlers.entity.QualityAsrCheckFormDataHandler;
import cc.comac.mom.entity.AsrCheckFormPrint;
import cc.comac.mom.util.ResultBean;
@Service
@RestController
public class QualityAsrCheckFormServiceImpl implements QualityAsrCheckFormService{

	@Autowired
	private UserUtil userUtil;
	@Autowired
	private QualityAsrCheckFormDataHandler qualityAsrCheckFormDataHandler;
	@Override
	public ResultBean batchUpdateAsrCheckFormAndDetail(@RequestBody QualityAsrCheckForm qualityAsrCheckForm) {
		ResultBean batchUpdateAsrCheckFormAndDetail = qualityAsrCheckFormDataHandler.batchUpdateAsrCheckFormAndDetail(qualityAsrCheckForm);
		return batchUpdateAsrCheckFormAndDetail;
	}

	@Override
	public ResultBean submitCheck(@RequestBody QualityAsrCheckForm qualityAsrCheckForm) {
		qualityAsrCheckForm.getInnerData().setQualityPlan(qualityAsrCheckForm.getInnerData().getCode());
        UsersDO usersDO=userUtil.getUserInfoByEcode(qualityAsrCheckForm.getInnerData().getQualityPlan());
        qualityAsrCheckForm.getInnerData().setQualityPlanUser(usersDO.getTruename());
		ResultBean submitCheck = qualityAsrCheckFormDataHandler.submitCheck(qualityAsrCheckForm);
		return submitCheck;
	}

	@Override
	public ResultBean submitReview(@RequestBody QualityAsrCheckForm qualityAsrCheckForm) {
		qualityAsrCheckForm.getInnerData().setQualityCheck(qualityAsrCheckForm.getInnerData().getCode());
		UsersDO usersDO=userUtil.getUserInfoByEcode(qualityAsrCheckForm.getInnerData().getQualityCheck());
		qualityAsrCheckForm.getInnerData().setQualityCheckUser(usersDO.getTruename());
		ResultBean submitReview = qualityAsrCheckFormDataHandler.submitReview(qualityAsrCheckForm);
		return submitReview;
	}

	@Override
	public ResultBean submitReject(@RequestBody QualityReject QualityReject) {
		UsersDO usersDO=userUtil.getUserInfoByEcode(QualityReject.getInnerData().getRejectUserJobNumber());
		QualityReject.getInnerData().setRejectUser(usersDO.getTruename());
		ResultBean submitReject = qualityAsrCheckFormDataHandler.submitReject(QualityReject);
		return submitReject;
	}

	@Override
	public ResultBean batchInsertAsrCheckForm(@RequestBody List<QualityAsrCheckForm> list) {
		ResultBean batchInsertAsrCheckForm = qualityAsrCheckFormDataHandler.batchInsertAsrCheckForm(list);
		return batchInsertAsrCheckForm;
	}

	@Override
	public ResultBean selectBySomefields(@RequestBody QualityAsrCheckForm qualityAsrCheckForm) {
		ResultBean selectBySomefields = qualityAsrCheckFormDataHandler.selectBySomefields(qualityAsrCheckForm);
		return selectBySomefields;
	}

	@Override
	public ResultBean submitToFile(@RequestBody QualityAsrCheckForm qualityAsrCheckForm) {
		qualityAsrCheckForm.getInnerData().setToFile(qualityAsrCheckForm.getInnerData().getCode());
		UsersDO usersDO=userUtil.getUserInfoByEcode(qualityAsrCheckForm.getInnerData().getToFile());
		qualityAsrCheckForm.getInnerData().setToFileUser(usersDO.getTruename());
		ResultBean submitToFile = qualityAsrCheckFormDataHandler.submitToFile(qualityAsrCheckForm);
		return submitToFile;
	}

	@Override
	public AsrCheckFormPrint printByCheckformId(@RequestParam long formId) throws Exception {
			AsrCheckFormPrint printByCheckformId = qualityAsrCheckFormDataHandler.printByCheckformId(formId);
		
		return printByCheckformId;
	}
	
}
